#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int m; cin >> m;
    vector<int> e(m + 1), en(m + 1);
    int h = 0, idx = 0;
    while(m--)
    {
        char c; cin >> c;
        if(c == 'H')
        {
            int x; cin >> x;
            e[++idx] = x;
            en[idx] = h;
            h = idx;
        }
        else if(c == 'D')
        {
            int k; cin >> k;
            if(k == 0) h = en[h];
            else en[k] = en[en[k]];
        }
        else if(c == 'I')
        {
            int k, x; cin >> k >> x;
            e[++idx] = x;
            en[idx] = en[k];
            en[k] = idx;
        }
    }
    while(h)
    {
        cout << e[h] << ' ';
        h = en[h];
    }
    return 0;
}